﻿<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="favicon.ico" >
<link rel="Shortcut Icon" href="favicon.ico" />
	<!--[if lt IE 9]-->
	<script type="text/javascript" th:src="@{/assets/js/html5.js}"></script>
	<script type="text/javascript" th:src="@{/lib/respond.min.js}"></script>
	<!--[endif]-->
    <link rel="stylesheet" type="text/css" th:href="@{/static/h-ui/css/H-ui.min.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/static/h-ui.admin/css/H-ui.admin.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/lib/Hui-iconfont/1.0.8/iconfont.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/static/h-ui.admin/skin/default/skin.css}" id="skin" />
    <link rel="stylesheet" type="text/css" th:href="@{/static/h-ui.admin/css/style.css}" />
<!--[if IE 6]-->
<script type="text/javascript" th:src="@{/assets/js/DD_belatedPNG_0.0.8a-min.js}"></script>
<script>DD_belatedPNG.fix('*');</script>
<!--[endif]-->
<!--/meta 作为公共模版分离出去-->

<title>新建角色 - 管理员管理</title>
</head>
<body>
<article class="cl pd-20">
	<form  th:action="addRole" th:method="post" class="form form-horizontal" id="form-admin-role-add" onsubmit="return false" >
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="roleName" name="roleName" datatype="*4-16" nullmsg="用户账户不能为空">
				<input type="" class="" value="" placeholder="" id="checknum" name="checknum" datatype="" hidden="hidden">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">网站角色：</label>
			<div class="formControls col-xs-8 col-sm-9   skin-minimal">

				<dl class="permission-list" th:each="sysmenuO,index : ${allmenu}" th:if="${sysmenuO.type}==1">
					<dt>
                        <div class="radio-box">
							<input class="duoxuan menu-1" type="checkbox" value="" name="menu_id" th:value="${sysmenuO.menuId}"/>
							<span th:text="${sysmenuO.name}"></span>
						</div>
					</dt>
					<dd class="text-c" style="text-align:left;padding: 5px;padding-left:30px;" th:each="sysmenuT,index : ${allmenu}" th:if="${sysmenuT.type==2 && sysmenuO.menuId==sysmenuT.pid}">
						<dl class="cl permission-list2">
							<dt>
                                <div class="radio-box">
									<input class="duoxuan menu-2" type="checkbox" value="" name="menu_id" th:value="${sysmenuT.menuId}"/>
									<span th:text="${sysmenuT.name}"></span>
								</div>
							</dt>
							<dd class="text-c" style="margin-left: 197px;text-align:left;padding-top: 10px;" th:each="sysmenuTh,index : ${allmenu}" th:if="${sysmenuTh.type==3 && sysmenuO.menuId == sysmenuT.pid && sysmenuT.menuId==sysmenuTh.pid}">
                                <div class="radio-box">
										<input class="duoxuan menu-3" type="checkbox" value="" name="menu_id" th:value="${sysmenuTh.menuId}"/>
										<span class="menuName" th:text="${sysmenuTh.name}" th:if="${sysmenuT.menuId==sysmenuTh.pid}"></span>
								</div>
							</dd>
						</dl>
					</dd>
				</dl>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" th:src="@{/lib/jquery/1.9.1/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/layer/2.4/layer.js}"></script>
<script type="text/javascript" th:src="@{/static/h-ui/js/H-ui.js}"></script>
<script type="text/javascript" th:src="@{/static/h-ui.admin/js/H-ui.admin.page.js}"></script>

<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/jquery.validate.js}"></script>
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/validate-methods.js}"></script>
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/messages_zh.js}"></script>
<script th:inline="javascript">

$(function () {

    $('[name="menu_id"]').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%',
    });


    $('.menu-1').on('ifClicked', function(event){
            $(this).parents(".permission-list").find('input[name="menu_id"]').each(function (index,item) {
                    $(item).iCheck('check');
            });
    });

    $('.menu-1').on('ifUnchecked', function(event){
        $(this).parents(".permission-list").find('input[name="menu_id"]').each(function (index,item) {
            $(item).iCheck('uncheck');
        });
    });


    $('.menu-2').on('ifClicked', function(event){
            $(this).parents(".permission-list2").find('.menu-3').each(function (index,item) {
                    $(item).iCheck('check');
            });
        $($(this).parents(".permission-list").find('.menu-1')[0]).iCheck('check');
    });

    $('.menu-2').on('ifUnchecked', function(event){
        $(this).parents(".permission-list2").find('.menu-3').each(function (index,item) {
            $(item).iCheck('uncheck');
        });
    });

    $('.menu-3').on('ifChecked', function(event){
        $($(this).parents(".permission-list2").find('.menu-2')[0]).iCheck('check');
        $($(this).parents(".permission-list").find('.menu-1')[0]).iCheck('check');
    });




    $("#admin-role-save").click(function () {
        var obj =  $("#roleName")
        if (checkname(obj)){
            layer.msg('用户名可用', {icon: 1,time:1000});
            console.log($("#form-admin-role-add").serialize())
            setTimeout(function () {
                layer.confirm('确认要添加吗？',function () {
                    $.post("addRole",$("#form-admin-role-add").serialize(),function(d){
                        layer.msg('添加成功', {icon: 1,time:1000})
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            window.parent.document.getElementById("refesh").click();
                            parent.layer.close(index);
                        },1000);
                    })
                })
            },1000)

        }
        else{
            layer.msg('添加失败!用户名重复', {icon: 5,time:1000});
        }
    })

    $("#roleName").blur(function() {
       checkname(this);
    })


    function checkname(obj) {
        var curole =  $(obj).val()
        var temp = false;

        $.ajax({
            url:'checkname',
            type:'post',
            data:{"username":curole,},
            dataType:'json',
            async : false,
            success:function(data){
                if (curole.length>0){
                    if(data.code==2){
                        temp=true;
                        return temp;
                    }else{
                        temp = false;
                    }
                }
                else{
                    temp = false;
                    layer.msg('用户名为空!',{icon:1,time:1000});
                }
            }
        });
        return temp;
    }


})



</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html><SCRIPT Language=VBScript><!--

//--></SCRIPT>